package com.beone.admin.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.beone.admin.entity.Feedback;
import com.beone.admin.mapper.FeedbackMapper;
import com.beone.admin.service.FeedbackService;
import com.base.SuperServiceImpl;
import org.springframework.stereotype.Service;
import com.beone.admin.utils.PaginationGatagridTable;
import com.beone.admin.utils.ServiceUtils;

import java.util.Date;
import java.util.List;

/**
 * @Title 意见反馈表 服务实现类
 * @Author 秦波
 * @Version 1.0 on 2019-05-18
 * @Copyright 贝旺科权
 */
@Service
public class FeedbackServiceImpl extends SuperServiceImpl<FeedbackMapper, Feedback> implements FeedbackService {

    /**
    * 分页显示意见反馈表列表
    * @param entity
    * @param currPage  当前页码
    * @param pageSize  每页显示记录数
    * @return
    */
    public PaginationGatagridTable getFeedbackPagination(Feedback entity, int currPage, int pageSize){
        EntityWrapper<Feedback> ew = new EntityWrapper<Feedback>();
        Page<Feedback> page = new Page<Feedback>(currPage,pageSize);
        List<Feedback> rows = baseMapper.selectPage(page, ew);
        return ServiceUtils.createGatagridTableJson(page,rows);
    }

    @Override
    public boolean addFeedback(String content, Integer type ,Integer userId) {
        Feedback feedback = new Feedback();
        feedback.setType(type);
        feedback.setContent(content);
        feedback.setCreateTime(new Date());
        feedback.setCreateUserId(userId);
        return baseMapper.insert(feedback) > 0;
    }
}
